<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>例子53-ES6/7常用语法介绍</title>
    </head>

    <body>
        <pre>
            <code>
                // 例子53

                async function f() {
                    return await 123;
                }

                f().then(v => console.log(v)) // 123

                //--------------------------------------------------------------------------

                async function f() {
                    await Promise.reject('出错了');
                }

                f()
                .then(v => console.log(v))
                .catch(e => console.log(e))	// Error: 出错了

                //--------------------------------------------------------------------------

                async function f() {
                await Promise.reject('出错了');
                    await Promise.resolve('hello world'); // 不会执行
                }
                f()	// Uncaught (in promise) 出错了

                //--------------------------------------------------------------------------

                async function f() {
                    try {
                        await Promise.reject('出错了');
                    } catch(e) {

                    }
                    return await Promise.resolve('hello world');
                }

                f()
                .then(v => console.log(v)) // "hello world"

                //--------------------------------------------------------------------------

                async function f() {
                    await Promise.reject('出错了')
                        .catch(e => console.log(e)); // 出错了
                    return await Promise.resolve('hello world');
                }

                f()
                .then(v => console.log(v))	// "hello world"
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/53.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>

</html>